import Vue from "vue";

import "normalize.css/normalize.css"; // A modern alternative to CSS resets

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import locale from "element-ui/lib/locale/lang/en"; // lang i18n

import "@/styles/index.scss"; // global css

import App from "./App";
import store from "./store";
import router from "./router";

import "@/icons"; // icon
import "@/permission"; // permission control

import dataV from "@jiaminghi/data-view";
Vue.use(dataV);

import VueWorker from 'vue-worker'
Vue.use(VueWorker)

const context = require.context("./components/daping/", true, /\.vue$/);
context.keys().forEach(k => {
  let component = context(k).default;
  if (component.name) {
    Vue.component(component.name, component);
  }
});

//三维组件   之后要放到components
// 自动加载    C:\Users\zxn\Desktop\FOUR\daping_front\src\views\tongyong\ThreeDimensional\components\linglong\cardchangqu.vue
const contextcom = require.context(
  "./views/tongyongnnn/ThreeDimensional/components/",
  true,
  /\.vue$/
);
contextcom.keys().forEach(k => {
  let component = contextcom(k).default;
  if (component.name) {
    Vue.component(component.name, component);
    // window.$vm.$component(component.name, component);
  }
});

const contextcom1 = require.context(
  "./views/tongyong/ThreeDimensional/components/",
  true,
  /\.vue$/
);
contextcom1.keys().forEach(k => {
  let component = contextcom1(k).default;
  if (component.name) {
    Vue.component(component.name, component);
    // window.$vm.$component(component.name, component);
  }
});

import _ from "lodash";
Vue.prototype._ = _;

import "./assets/icons/iconfont";
import "./assets/tianqi/iconfont";

import IconSvg from "./components/IconSvg"; // svg组件

// 注册全局组件（register global）
Vue.component("icon-svg", IconSvg);

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */
import { mockXHR } from "../mock";

// if (process.env.NODE_ENV != 'zxn') {
//   mockXHR()
// }

import scroll from "vue-seamless-scroll";
Vue.use(scroll);
// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI);

Vue.config.productionTip = false;

if (typeof XE !== "undefined") {
  // 如果XE存在，说明EarthSDK已载入
  // eslint-disable-next-line no-console
  console.log("当前正在使用EarthSDK开发！");
  /* eslint-disable*/
  function startup() {
    window.$vm =  new Vue({
      el: "#app",
      router,
      store,
      data() {
        return {
          //-----------------------三维地球依赖-----------------------------
          _earth: {},

          //----------------------------其他-----------------------------------
          setting: {
            scale: 1,
            data: { interval: 20000 }
          },
          permission: {
            editmenu: {},
            allocMenu: {},
            allocResource: {},
            dataSetting: {}
          },
          efficiency_data: ''
        };
      },
      render: h => h(App)
    });
  }

  // 1 XE.ready()会加载Cesium.js等其他资源，注意ready()返回一个Promise对象。
  XE.ready()
    .then(() => {
      // 加载标绘插件
      const p1 = XE.HTML.loadJS(
        "/js/earthsdk/XbsjEarth-Plugins/plottingSymbol/plottingSymbol.js"
      );
      const p2 = XE.HTML.loadJS(
        "/js/earthsdk/XbsjEarth-Plugins/customPrimitive/customPrimitive.js"
      );
      const p3 = XE.HTML.loadJS(
        "/js/earthsdk/XbsjEarth-Plugins/customPrimitiveImage/customPrimitiveImage.js"
      );
      const p5 = XE.HTML.loadJS(
        "/js/earthsdk/XbsjEarth-Plugins/plottingSymbol2/plottingSymbol2.js"
      );
      const p4 = XE.HTML.loadJS("/js/earthsdk/scripts/three.min.js"); // 部分图元需要加载three.js
      return Promise.all([p1, p2, p3, p5]);
    })
    .then(startup);
} else if (typeof Cesium !== "undefined") {
  // 如果XE不存在，存在Cesium，则此时用纯Cesium进行开发
  console.log("当前正在使用纯Cesium开发！");
  new Vue({
    el: "#app",
    router,
    store,
    data() {
      return {
        permission: {
          setting: {
            scale: 1
          },
          editmenu: {},
          allocMenu: {},
          allocResource: {}
        }
      };
    },
    render: h => h(App)
  });
}
